<?php

namespace App\Http\Controllers\Home;


use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class DuanzuController extends Controller
{



    public function index()
    {
        //获取车型数据
        $carModel = DB::table('carmodel')->get();
//        dd($carModel);
        //获取汽车品牌数据
        $carBrand = DB::table('brand')->get();
//        dd($carBrand);
        //获取城市信息
        $city = DB::table('city')->get();
//        dd($city);
        return view('home.duanzu')->with('carModel',$carModel)->with('carBrand',$carBrand)->with('city',$city);
    }

    public function citystore()
    {
        if($input = Input::all()){
            $ctid = $input['ctid'];
//            dd($ctid);
            $data = DB::table('store')->where('zc_city_ctid',$ctid)->get();
//           
            return $data;
        }

    }
    public function formdata()
    {
        if($input =Input::all()){
//            dd($input);
            $store_id = DB::table('store')->where('mname',$input['qcplace'])->value('menid');
//            dd($store_id);
            $data =DB::table('car')->join('carconfig','fid','=','zc_carconfig_fid')->where('zc_store_menid',$store_id)->get();
//            dd($data);

            return $data;
        }

    }
    public function select()
    {
        if($input = Input::all()){
//            dd($input);
//                dd($this->carData);
            if($input['carmodel']!='不限'){
                $zc_carModel_mid = DB::table('carmodel')->where('mname',$input['carmodel'])->value('mid');
                $data1 = DB::table('car')->join('carconfig','fid','=','zc_carconfig_fid')->where('zc_carModel_mid',$zc_carModel_mid)->get();
//
            }else{
                $data1 = DB::table('car')->join('carconfig','fid','=','zc_carconfig_fid')->get();
            }

            if($input['brand']!='不限'){
                $zc_brand_bid = DB::table('brand')->where('bname',$input['brand'])->value('bid');
                $data2 = DB::table('car')->join('carconfig','fid','=','zc_carconfig_fid')->where('zc_brand_bid',$zc_brand_bid)->get();

            }else{
                $data2 = DB::table('car')->join('carconfig','fid','=','zc_carconfig_fid')->get();
            }
            if($input['price']!='不限'){
                $data3 = DB::table('car')->join('carconfig','fid','=','zc_carconfig_fid')->where('cprice','<',$input['price'])->get();


            }else{
                $data3 = DB::table('car')->join('carconfig','fid','=','zc_carconfig_fid')->get();
            }
            $dataTemp=[];
            foreach ($data1 as $v){
                foreach ($data2 as $vv){
                    if($v == $vv){
                        $dataTemp[]  = $v;
                    }
                }
            }
            foreach($dataTemp as $v){
                foreach($data3 as $vv){
                    if($v == $vv){
                        $data[] = $v;
                    }
                }
            }
//            dd($data);
            $data = json_encode($data);
            return $data;

        }

    }

    public function save()
    {

        $input = Input::all();
//        dd($input);
        session(["car_id"=>$input['car_id']]);
        session(["borrow_menid"=>$input['borrow_menid']]);
        session(["return_menid"=>$input['return_menid']]);
        session(["borrow_time"=>$input['borrow_time']]);
        session(["return_time"=>$input['return_time']]);
        return 1;
    }


}
